import 'package:fate_blind_box/network/http_request.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:im_flutter_sdk/im_flutter_sdk.dart';

import 'black_user_model.dart';

class BlackUserListController extends GetxController {
  String itemViewId = 'itemViewId';
  List dataList = [];
  List userList = [];

  void initData() async {
    try {
      List<String> blackList =
          await EMClient.getInstance.contactManager.getBlockListFromServer();
      dataList.addAll(blackList);

      var res = await HttpRequest.request('easemob/friend/blacklist',
          params: {'easenames': dataList});
      if (res is Map) {
        BlackUserModel userModel = BlackUserModel.fromJson(res);
        userList.addAll(userModel.data ?? []);
        update([itemViewId]);
      }
    } on EMError catch (e) {
      debugPrint("error code: ${e.code}, desc: ${e.description}");
    }
  }
}
